package com.qfedu.vhr.framework.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @author baize
 * @date 2023/1/12
 * @site www.qfedu.com
 */
@Configuration
//开启websocket消息代理
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry
                //配置端点（类似于我们常说的接口），这个端点是建立连接的端点
                //这个地方需要注意，请求的前缀不能用 /ws
                .addEndpoint("/myws/ep")
                //设置允许的域
                .setAllowedOrigins("http://localhost:8080")
                //开启 sockjs 支持
                .withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //设置消息代理的路径
        registry.enableSimpleBroker("/queue", "/topic");
    }
}
